package com.zhang.zxx.boot.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhang.zxx.boot.domain.dto.SysLogPageDTO;
import com.zhang.zxx.boot.entity.DO.SysLog;
import com.zhang.zxx.boot.mapper.SysLogMapper;
import com.zhang.zxx.boot.service.SysLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.function.Predicate;


/**
 * 日志表: 服务类实现类
 *
 * @author zhangxiaoxiang
 * @date 2021-12-12
 */
@Slf4j
@Service
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements SysLogService {

    @Override
    public IPage<SysLog> sysLogPage(SysLogPageDTO dto) {
        LambdaQueryWrapper<SysLog> query = new LambdaQueryWrapper<>();
        Predicate<Object> p = ObjectUtil::isNotEmpty;
        query.eq(p.test(dto.getOperName()), SysLog::getOperName, dto.getOperName())
                .like(p.test(dto.getBusinessName()), SysLog::getBusinessName, dto.getBusinessName())
                .eq(p.test(dto.getMethod()), SysLog::getMethod, dto.getMethod())
                .ge(p.test(dto.getCreateDate()), SysLog::getCreateDate, dto.getCreateDate());
        return this.page(dto, query);

    }
}
